import axios from 'axios'

export const ExceptionUtil = (msg) => {
  // console.log(msg)
  if (msg != null && (msg.indexOf('违反唯一约束条件') > -1 || msg.indexOf('unique constraint') > -1)) {
    return msg
  }
  return msg
  // return msg.replace(/[A-Za-z0-9\:\_\.\ \-\(\)\#\,\[\]\;\?]/ig,"");
}

// 创建axios实例
const service = axios.create({
  baseURL: '', // api 的 base_url
  timeout: 100000000, // 请求超时时间
  withCredentials: true,
  validateStatus: function(status) {
    return status < 600 // 状态码在大于或等于500时才会 reject
  }
})

// response 拦截器
service.interceptors.response.use(
  response => {
    /**
     * code为非0是抛错 可结合自己业务进行修改
     */
    // console.log(response)
    try {
      const res = response.data
      return res
    } catch (error) {
      return Promise.reject(error)
    }
    
  },
  (error) => {
   
    return Promise.reject(error)
  }
)

export default service
